package com.ojoin.trade.common.utils;

import com.ojoin.trade.common.SensitiveEnum;
import org.apache.commons.lang3.StringUtils;

/**
 * Created by huanggc on 2016/8/12.
 */
public class SensitiveToMaskUtils {


    public static String sensitiveFilter(String src,SensitiveEnum sen) {
        String ret = null;
        switch (sen) {
            case BANK_NO:
                if(StringUtils.isNotEmpty(src)&&src.length()>8) {
                    String pre = src.substring(0, 4);
                    String end = src.substring(src.length() - 4);
                    String middle = CommonUtils.dup("*", src.length() - 8);
                    ret = pre + middle + end;
                }
                    break;
            case MOBILE:
                if(StringUtils.isNotEmpty(src)&&src.length()>8) {
                    ret = CommonUtils.maskMobile(src);
                }
                    break;
            case ID_CARD:
                if(StringUtils.isNotEmpty(src)&&src.length()>10) {
                    String pre = src.substring(0, 5);
                    String end = src.substring(src.length() - 5);
                    String middle = CommonUtils.dup("*", src.length() - 10);
                    ret = pre + middle + end;
                }
                break;
            case NAME:
                if(StringUtils.isNotEmpty(src)&&src.length()>1) {
                    String pre = src.substring(0, 1);
                    String middle = CommonUtils.dup("*", src.length() - 1);
                    ret = pre + middle;
                }
                break;

            default:

        }
        return ret;
    }


}
